'use strict';

angular.module('snPaas_om')
	.controller('MysqlCompDetailCtrl',['$scope','baseUrl','ngDialog','mysqlMonitorStore','mysqlClusterStore',function($scope,baseUrl,ngDialog,mysqlMonitorStore,mysqlClusterStore){

		var vm = $scope;
		vm.comp = vm.$stateParams.comp;
		vm.id = vm.$stateParams.id;



		vm.baseUrl = baseUrl.static;
		vm.loading = false;

		mysqlMonitorStore.componentMonit(vm.id,vm.comp).then(function(data){
			vm.monitList = data;
		});
		mysqlClusterStore.detail(vm.id).then(function(data){
			vm.clusterName = data.deploymentName;
		});



		vm.start = function(monit){
			monit.loading = true;
			monitorStore.start(monit.index,vm.comp,vm.clusterId).then(function(){
			monit.loading = false;

				monitorStore.componentMonit(vm.clusterId,vm.comp).then(function(data){
					vm.monitList = data;
				});
			});
		};
		vm.restart = function(monit){
			monit.loading = true;
			monitorStore.restart(monit.index,vm.comp,vm.clusterId).then(function(){
			monit.loading = false;
				monitorStore.componentMonit(vm.clusterId,vm.comp).then(function(data){
					vm.monitList = data;
				});
			});
		};
		vm.stop = function(monit){
			monit.loading = true;
			monitorStore.stop(monit.index,vm.comp,vm.clusterId).then(function(){
			monit.loading = false;
				monitorStore.componentMonit(vm.clusterId,vm.comp).then(function(data){
					vm.monitList = data;
				});
			});
		};
	}]);